package com.eco.fanliapp.admin.controller.web;


import com.eco.fanliapp.admin.annotation.SysLogAnnotation;
import com.eco.fanliapp.admin.common.BaseController;
import com.eco.fanliapp.common.response.ServerResponse;
import com.eco.fanliapp.entity.SyUserUnboundedOrderApply;
import com.eco.fanliapp.service.ISyUserUnboundedOrderApplyService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2019-12-19
 */
@RestController
@RequestMapping("sy/unboundedOrder")
public class SyUserUnboundedOrderController extends BaseController {

    @Autowired
    private ISyUserUnboundedOrderApplyService syUserUnboundedOrderApplyService;

    /**
     *订单绑定列表
     * @param params
     * @return
     */
    @GetMapping("/list")
    @ResponseBody
    public ServerResponse list(@RequestParam HashMap<String, Object> params){
        return syUserUnboundedOrderApplyService.selectUnboundedOrder(params);
    }

    /**
     *更新订单绑定列表
     * @param list
     * @return
     */
    @PostMapping("/update")
    @ResponseBody
    @SysLogAnnotation(value = "更新了绑定订单的列表",userType = 2)
    public ServerResponse update(@RequestParam(value="list",required=false)List<Integer> list){
        if(CollectionUtils.isEmpty(list)){
            return ServerResponse.createByErrorMessage("批量未传递id参数");
        }
        List<SyUserUnboundedOrderApply> listParam = syUserUnboundedOrderApplyService.selectBatchTableId(list);
        boolean bool = syUserUnboundedOrderApplyService.updateBatchById(listParam);
        return ServerResponse.createBySuccessMessage(bool?"批量无效处理成功":"批量无效处理失败");
    }


    /**
     * 导出绑定的列表
     * @param response
     * @param params
     */
    @GetMapping("/detail/export")
    @SysLogAnnotation(value = "导出了绑定订单的列表",userType = 2)
    public void exportDetailList(HttpServletResponse response, @RequestParam HashMap<String, Object> params) {

        syUserUnboundedOrderApplyService.exportDetailList(response, params);
    }


}
